//C13:ep3_5.c: read data from file to console.
#include <stdio.h>
#include <stdlib.h>

struct student_st
{
    char name[15];
    int num;
    int age; 
    char sex;
} stud[4];

int main(void)
{
    int i;
    FILE *fp;
    if((fp = fopen("file1.txt","r")) == NULL)
    {
        fprintf(stderr, "cannot open file!");
        exit(1);
    }

    for(i = 0; i < 4; i++)
    {
        fseek(fp, i * sizeof(struct student_st), 0);
        fread(&stud[i], sizeof(struct student_st), 1, fp);
        printf("%s %d %d %c\n", stud[i].name, stud[i].num, stud[i].age,
                stud[i].sex);
    }

    fclose(fp);
    exit(0);
}
